import { CoolController, BaseController } from '@cool-midway/core';
import {DemoShipsEntity} from "../../entity/ships";
import {Context} from "koa";

/**
 * 商品模块-商品信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: DemoShipsEntity,
  // 向表插入当前登录用户ID
  insertParam: (ctx => {
    return {
      // 获得当前登录的后台用户ID，需要请求头传Authorization参数
      userId: ctx.admin.userId
    }
  }),
  // 分页查询配置
  pageQueryOp: {
    // 让dovecotName字段支持模糊查询
    //keyWordLikeFields: ['contestName'],
    //select: ['a.*', 'b.name AS pigeonClubName', 'c.typeName'],
    // 4.x新增
    // join: [
    //   {
    //     entity: BaseSysUserEntity,
    //     alias: 'b',
    //     condition: 'a.userId = b.id',
    //     type: 'innerJoin',
    //   },
    //   {
    //     entity: DemoContestTypeEntity,
    //     alias: 'c',
    //     condition: 'a.contestTypeId = c.id',
    //     type: 'innerJoin',
    //   },
    // ],
    // 增加其他条件
    where: async (ctx: Context) => {
      return [
        ['a.userId = :userId', { userId: ctx.admin.userId }]
      ]
    },
  }
})
export class AdminDemoShipsController extends BaseController {}
